package edu.ucsc.gameAI.hfsm;

import java.util.ArrayList;
import java.util.Collection;

import pacman.game.Game;
import edu.ucsc.gameAI.IAction;

public class HState implements IHState {

	protected IAction entryAction;
	protected IAction exitAction;
	protected IAction action;
	protected Collection<IHTransition> transitions;
	protected IHFSM parent;
	protected String name = "unnamed";

	public HState() {
		transitions = new ArrayList<IHTransition>();
	}

	public HState(String string) {
		name = string;
		transitions = new ArrayList<IHTransition>();
	}

	@Override
	public IResult update(Game game) {
		IResult result = new Result();
		result.setActions(new ArrayList<IAction>());
		result.setTransition(null);
		result.setLevel(0);
		return result;
	}

	@Override
	public Collection<IHState> getStates() {
		Collection<IHState> states = new ArrayList<IHState>();
		states.add(this);
		return states;
	}

	@Override
	public void setStates(Collection<IHState> states) {
		return;
	}

	@Override
	public IAction getAction() {
		return action;
	}

	@Override
	public void setAction(IAction action) {
		this.action = action;
	}

	@Override
	public IAction getEntryAction() {
		return entryAction;
	}

	@Override
	public void setEntryAction(IAction action) {
		entryAction = action;
	}

	@Override
	public IAction getExitAction() {
		return exitAction;
	}

	@Override
	public void setExitAction(IAction action) {
		exitAction = action;
	}

	@Override
	public Collection<IHTransition> getTransitions() {
		return transitions;
	}

	@Override
	public void setTransitions(Collection<IHTransition> transitions) {
		transitions.addAll(transitions);
	}

	@Override
	public void addTransition(IHTransition transition) {
		if (null == transitions) {
			transitions = new ArrayList<IHTransition>();
		}
		if (null != transition) {
			transitions.add(transition);
		}
	}

	@Override
	public IHFSM getParent() {
		return parent;
	}

	@Override
	public void setParent(IHFSM parent) {
		this.parent = parent;
	}
	
	public String getName(){
		return name;
	}

}
